<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel>
                        <f:facet name="header" >
                            <h:outputLabel value="OPD BILL SEARCH TO PAY "/>

                            <h:panelGrid columns="7" >
                                <p:calendar id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                                </p:calendar>
                                <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                                </p:calendar>
                                <p:commandButton id="btnSearch" ajax="false" value="Search All" action="#{searchController.createOpdBathcBillPreTable}"/>
                                <p:commandButton id="btnSearch2" ajax="false" value="Search Paid Only" action="#{searchController.createOpdBathcBillPreTablePaidOnly}"/>
                                <p:commandButton id="btnSearch3" ajax="false" value="Search Not Paid Only" action="#{searchController.createOpdBathcBillPreTableNotPaidOly}"/>
                                <h:outputLabel />
                                <p:commandButton  ajax="false" value="Pharmacy Payment" action="/pharmacy/pharmacy_search_pre_bill.xhtml"/>
                                
                                <p:spacer height="30"/><h:outputLabel/><h:outputLabel/><h:outputLabel/><h:outputLabel/><h:outputLabel/><h:outputLabel/>

                                <h:outputLabel value="Bill No"/>
                                <h:outputLabel value="Patient Name"/>                               
                                <h:outputLabel value="Total"/>
                                <h:outputLabel value="Net Total"/>   
                                <h:outputLabel/><h:outputLabel/><h:outputLabel/>

                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                                <p:inputText autocomplete="off" value="#{searchController.searchKeyword.patientName}" />
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.total}" />
                                <p:inputText autocomplete="off" value="#{searchController.searchKeyword.netTotal}"/>
                                <h:outputLabel/><h:outputLabel/><h:outputLabel/>

                            </h:panelGrid>

                        </f:facet>

                        <p:defaultCommand target="btnSearch"/>

                        <p:dataTable 
                            rowIndexVar="i"
                            id="tblBills" 
                            value="#{searchController.aceptPaymentBills}" 
                            var="bill"   
                            paginator="true"
                            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                            rowsPerPageTemplate="5,10,15"
                            >

                            <p:column headerText="No" styleClass="alignTop">
                                <h:outputLabel value="#{i+1}"/>
                            </p:column>

                            <p:column headerText="Bill No" >
                                <h:outputLabel value="#{bill.deptId}"  ></h:outputLabel>
                            </p:column>   
                             <p:column headerText="Name" >
                                 <h:outputLabel value="#{bill.patient.person.nameWithTitle}"  ></h:outputLabel>
                            </p:column>   
                            <p:column headerText="Billed at"  >
                                <h:outputLabel value="#{bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" 
                                                   value="#{bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>                             
                            </p:column>                 
                            <p:column headerText="Billed by" >
                                <h:outputLabel value="#{bill.creater.webUserPerson.name}" >                                      
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled By " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.creater.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>                               
                            </p:column>  
                            <p:column headerText="Net Value" style="text-align: right; padding-right: 10px;" >

                                <h:outputLabel value="#{bill.total - bill.discount}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>

                            </p:column>

                            <p:column headerText="Accept">
                                #{bill.referenceBill.balance}
                                <p:commandButton ajax="false"  value="Accept Payment" 
                                                 action="#{opdPreSettleController.toSettleBatch(bill)}" 
                                                 disabled="#{(bill.referenceBill.balance le 0.0 )or bill.cancelled}" >
                                </p:commandButton>
                            </p:column>
                            
                            <p:column headerText="Reprint">
                                <p:commandButton ajax="false"  
                                                 value="Reprint" 
                                                 action="bill_print" 
                                                 disabled="#{bill.referenceBill.balance ge 0.0}" >
                                    <f:setPropertyActionListener value="#{bill.referenceBill.forwardReferenceBills}" target="#{opdPreBillController.bills}" />
                                </p:commandButton>
                            </p:column>

                        </p:dataTable>


                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
